<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增mater')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-mater-add">
            <input name="deptId" type="hidden" id="treeId"/>
            <div class="form-group">
                <label class="col-sm-3 control-label">归属项目：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input name="deptName" onclick="selectDeptTree()" id="treeName" type="text" placeholder="请选择归属部门" class="form-control">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">姓名：</label>
                <div class="col-sm-8">
                    <input name="materName" class="form-control" type="text" placeholder="请输入姓名" autocomplete="off" maxlength="30" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">手机号：</label>
                <div class="col-sm-8">
                    <input name="materPhone" class="form-control" type="text" placeholder="请输入手机号码" maxlength="11" autocomplete="off" required>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/mater"
        $("#form-mater-add").validate({

            onkeyup: false,
            rules:{
                materPhone:{
                    isPhone:true,
                    remote: {
                        url: prefix + "/checkPhoneUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "materPhone": function () {
                                return $.common.trim($("#phonenumber").val());
                            }
                        },
                        dataFilter: function (data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
            },
            messages: {
                "loginName": {
                    remote: "用户已经存在"
                },
                "email": {
                    remote: "Email已经存在"
                },
                "phonenumber":{
                    remote: "手机号码已经存在"
                }
            },
            // 如果为true，当表单得到焦点时，移除在该表单上的errorClass并隐藏所有错误消息
            focusCleanup: true
        });

        /* 用户管理-新增-选择部门树 */
        function selectDeptTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-mater-add').serialize());
            }
        }
    </script>
</body>
</html>